#!/bin/bash
# 构建 Snap 包

set -e

# 配置参数
SNAP_NAME="mirror-tool"
SNAP_DIR="snap"
OUTPUT_DIR="../build/snap"

# 检查 Snapcraft
if ! command -v snapcraft &> /dev/null; then
    echo "安装 Snapcraft..."
    sudo apt install -y snapd
    sudo snap install snapcraft --classic
fi

# 清理旧构建
rm -rf "${SNAP_NAME}_"*.snap

# 执行构建
snapcraft clean --destructive-mode
snapcraft --destructive-mode

# 移动输出文件
mkdir -p "$OUTPUT_DIR"
mv "${SNAP_NAME}_"*.snap "$OUTPUT_DIR/"

echo "构建成功: $OUTPUT_DIR/${SNAP_NAME}_*.snap"